package com.cradom.event.utils;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import org.springframework.web.multipart.MultipartFile;

import com.cradom.event.model.Image;

public class FilesUpload {
	/**
	 * 上传图片，返回一个图片对象
	 * @param file
	 * @param root
	 * @param children_id
	 * @param i
	 * @return
	 * @throws Exception
	 * @throws IOException
	 */
	public static Image filesUpload(MultipartFile file, String root, String children_id, int i)
			throws Exception, IOException {
		String id = UUIDUtil.returnStr(UUID.randomUUID());
		Image image = new Image();
		image.setId(id);
		file.transferTo(new File(root + "/" + children_id + i + ".jpg"));
		image.setUrl("/upload/" + children_id + i + ".jpg");
		image.setChildren_id(children_id);
		image.setType("jpg");
		return image;
	}
}
